/***************************************************************************
 *   Copyright (C) 2008 by Dmitry Malakhov                                 *
 *   abr_mail@mail.ru                                                      *
 *                                                                         *
 *   This file is part of game Fifteens                                    *
 *                                                                         *
 *   Fifteens is free software; you can redistribute it and/or modify      *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   Fifteens is distributed in the hope that it will be useful,           *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

/*main.c*/

#if HAVE_CONFIG_H
#include <config.h>
#endif

#include <glib/gi18n.h>
#include <gtk/gtk.h>
#include <string.h>

#include "data.h"

int main(int argc, char *argv[])
{
	setlocale(LC_ALL, "");

	bindtextdomain(GETTEXT_PACKAGE, FIFTEENS_LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain(GETTEXT_PACKAGE);

	gtk_init (&argc, &argv);

	window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	char *title, *prod_name = _("Fifteens v");

	title = (char*)malloc((strlen(prod_name) + strlen(VERSION) + 1) * sizeof(char));

	memcpy(title, prod_name, strlen(prod_name) + 1);
	memcpy(title + strlen(prod_name), VERSION, strlen(VERSION) + 1);
	
	gtk_window_set_title(GTK_WINDOW (window), title);

	gtk_window_set_default_size(GTK_WINDOW(window), 450, 480);
	GdkGeometry gdkGeometry;
	gdkGeometry.min_width = 450;
	gdkGeometry.min_height = 480;
	gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &gdkGeometry, GDK_HINT_MIN_SIZE);

	gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);

	g_signal_connect_swapped(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);

	GtkWidget *box_common = gtk_vbox_new(FALSE, 0);
	gtk_container_add(GTK_CONTAINER(window), box_common);

	make_menu(box_common);
	make_buttons(box_common);
	init_values();

	g_timeout_add(2, (GSourceFunc) on_timeout, NULL);

	gtk_widget_show(box_common);
	gtk_widget_show(window);

	gtk_window_set_resizable(GTK_WINDOW(window), FALSE);

	gtk_main();
	return 0;
}
